package stock;

import java.util.List;

import org.hibernate.Session;

import common.Logger;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class StockQQRunable implements Runnable {

	private JSONArray listjson;
	public static Logger logger = Logger.getLogger(Object.class);

	private int start;
	private int limit;

	public StockQQRunable(JSONArray listjson, int start, int limit) {

		this.start = start;
		this.limit = limit;
		this.listjson = listjson;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		Session session1 = ContextUtil.getSessionFactory1().openSession();

		session1.getTransaction().begin();

		for (int i = start; i < limit; i++) {
			System.out.println("加载qq"+listjson.getJSONObject(i).getString("code"));
			JSONObject js = listjson.getJSONObject(i);
			StockQQ stockqq =null;
			try {
				 stockqq = (StockQQ) js.toBean(js, StockQQ.class);
			} catch (Exception e) {
				System.out.println("转换出错");
				continue;
			}
			
			stockqq.setCreateTime(DateTools.getCurrentDateTime());
			// List<StockQQ> str = session1.createSQLQuery(sql1).setParameter(0,
			// stockqq.getDate())
			// .setParameter(1, stockqq.getCode()).list();
			// if (str.size() <= 0 || null == str) {
			System.out.println("---QQ接口---" + stockqq.getCode() + "-------i==" + i);
			// session1.save(stockqq);
			// } else {
			session1.save(stockqq);
		}

		session1.getTransaction().commit();
		session1.clear();
		session1.close();

	}

}
